<template>
  <NavBack title="我的收货地址"></NavBack>
  <van-address-list
    :list="list"
    default-tag-text="默认"
    @add="onAdd"
    @edit="onEdit"
    @select="click01"
    v-model="chosenAddressId"
  />
</template>

<script>
import NavBack from "../../components/NavBack.vue";
export default {
  data() {
    return {
      list: [],
      chosenAddressId: "",
    };
  },
  components: {
    NavBack,
  },
  computed: {},
  created() {
    this.$http({
      url: "/address/list",
      params: {
        userid: localStorage.getItem("userid"),
      },
    }).then((res) => {
      if (res.data.code === "200") {
        res.data.data.forEach((item) => {
          item['id'] = item.addressid
          item["address"] =
            item.province + item.city + item.county + item["addressDetail"];
          // console.log(item.addressid);
          // this.chosenAddressId = item.addressid;
        });
        this.list = res.data.data;
        console.log(this.list);
        // addressid
        // console.log(this.list[0].addressid);
        this.chosenAddressId = res.data.data.filter(item=>item.isDefault)[0].addressid
        
        
      }
    });
  },
  methods: {
    onAdd() {
      this.$router.push("/NewAddress");
    },
    onEdit(info) {
      this.$router.push({
        path: "/ChangeAdd",
        query: {
          infodata: JSON.stringify(info),
        },
      });
    },
    click01(info) {
      console.log(info);
      this.chosenAddressId = info.addressid
      this.$router.push({
        path: "/confirmorder",
        query: {
          userid: info.userid,
        },
      });
    },
  },
};
</script>

<style>
</style>